﻿using System;
using System.Diagnostics;
using System.Drawing;
using System.Windows.Forms;

namespace OsuKeyboard
{
    public partial class ColorWheelPicker : Form
    {
        public ColorWheelPicker()
        {
            InitializeComponent();
        }

        private Color DefaultColor;     // 默认颜色，用于取消设置后恢复上次颜色
        private Color CurrentColor;     // 当前颜色，用于存储当前临时选择的颜色
        
        private void ColorWheelPicker_Load(object sender, EventArgs e)
        {
            CheckLanguage();
            FormMain mainForm = (FormMain)this.Owner;
            CurrentColor = DefaultColor = mainForm.LEDValue;
            colorEditorManager.Color = DefaultColor;
        }
        // 界面语言设置
        private void CheckLanguage()
        {
            FormMain mainForm = (FormMain)this.Owner;
            this.Text = Languages.GetLang("LedColorPicker") + "-" + mainForm.SelectedLB.Text; ;
            PickerMode.Text = Languages.GetLang(PickerMode.Name);
            SettingMode0.Text = Languages.GetLang(SettingMode0.Name);
            SettingMode1.Text = Languages.GetLang(SettingMode1.Name);
            Accept.Text = Languages.GetLang(Accept.Name);
            Cancel.Text = Languages.GetLang(Cancel.Name);
        }
        // 颜色管理器色彩变更事件
        private void colorEditorManager_ColorChanged(object sender, EventArgs e)
        {
            SelectedColor.BackColor = colorEditorManager.Color;
			if (SettingMode1.Checked) RealTimePicker.Enabled = true;
		}
		// LED实时调试模式定时设置器(使用定时器是为了减少Flash读写次数)
		private void RealTimePicker_Tick(object sender, EventArgs e)
		{
			if (CurrentColor.ToArgb() != colorEditorManager.Color.ToArgb())
			{
				CurrentColor = colorEditorManager.Color;
				FormMain mainForm = (FormMain)this.Owner;
				mainForm.RealTimeColorLed = CurrentColor;
			}
			else
			{
				RealTimePicker.Enabled = false;
			}
			Debug.WriteLine("RealTimePicker: " + DateTime.Now.ToLongTimeString().ToString());
        }

        // 确定设置当前选中的颜色
        private void Accept_Click(object sender, EventArgs e)
        {
            FormMain mainForm = (FormMain)this.Owner;
            mainForm.LEDValue = colorEditorManager.Color;
            this.Close();
        }

        // 取消设置当前选中的颜色
        private void Cancel_Click(object sender, EventArgs e)
        {
            FormMain mainForm = (FormMain)this.Owner;
            mainForm.LEDValue = DefaultColor;
            this.Close();
        }
    }
}
